home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12493 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: casbah.acns.nwu.edu!muzaffar
  2. From: muzaffar@casbah.acns.nwu.edu (Usman Muzaffar)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Sort Function
  5. Date: 1 Apr 1996 12:20:45 GMT
  6. Organization: Northwestern University, Evanston IL
  7. Message-ID: <4johmt$jee@news.acns.nwu.edu>
  8. References: <4jmq99$cqi@freenet-news.carleton.ca>
  9. NNTP-Posting-Host: casbah.acns.nwu.edu
  10.  
  11. In article <4jmq99$cqi@freenet-news.carleton.ca>,
  12. Jerry Boyd <aq436@FreeNet.Carleton.CA> wrote:
  13. >
  14. >
  15. >How would I WRITE a function (called sort3) that would 
  16. >sort three integers (in assending order) by using pointers
  17. >and NOT arrays?
  18.  
  19. I'm not sure what you mean by the caveat. I think most of the
  20. programmers here would agree that pointers and arrays are really two
  21. sides of the same coin - they're both a means of accesing memory;
  22. remember, a[6] is exactly the same as saying *(a+6). The brackets are
  23. just a convenient way of writing it.
  24.  
  25. So if you mean you want your sort3() function to not use brackets,
  26. then just replace a[1] with *(a+1) and there you have it. The
  27. alternative is even more straightforard, if sort3 is passed it's
  28. arguments: sort3(int *a, int *b, int*c), then just use a series of
  29. inequaility operators to determine the answer and then use *a = xxx to
  30. actually set the values.  Piece of cake.
  31.  
  32. -usman
  33.  
  34.  
  35.  
  36.